package gui.cen.table;

import gui.Segl2;
import gui.cen.Center;
import gui.cen.south.HeatMap;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class TableDisp extends JPanel{

    private TablePane tp;
    private TableOpts to;
    private Predator pred;
    private Segl2 segl2;
    private JScrollPane scr;
    private JLayeredPane lp;

    public TableDisp(Center center, Segl2 segl2){
        this.setLayout(new BorderLayout());
        this.segl2 = segl2;
        lp = new JLayeredPane();
        lp.setPreferredSize(new Dimension(segl2.getWidth()-4, segl2.getHeight() - HeatMap.HEIGHT_OF_HEATMAP - 42));

        lp.setBackground(new Color(102, 102, 102));
        this.setBackground(new Color(102, 102, 102));

        tp = new TablePane(segl2);
        scr = new JScrollPane(tp);
        scr.setBackground(new Color(102, 102, 102));
        scr.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scr.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        scr.setBounds(0, 0, segl2.getWidth()-4, segl2.getHeight() - HeatMap.HEIGHT_OF_HEATMAP - 42);
        lp.add(scr, new Integer(1));

        to = new TableOpts(center);
        to.setBounds((segl2.getWidth() - (Center.WIDGE_WIDTH + Center.WIDGE_SIDE)), Center.WIDGE_TOP, Center.WIDGE_WIDTH, TableOpts.HEIGHT_OF_OPTIONS);
        lp.add(to, new Integer(2));

        pred = new Predator(center);
        pred.setBounds((segl2.getWidth() - (Center.WIDGE_WIDTH + Center.WIDGE_SIDE)), (segl2.getHeight() - (HeatMap.HEIGHT_OF_HEATMAP + Predator.HEIGHT_OF_PREDATOR + 90)), Center.WIDGE_WIDTH, Predator.HEIGHT_OF_PREDATOR);
        lp.add(pred, new Integer(3));
        this.add(lp, BorderLayout.CENTER);
        
        this.addComponentListener(new ComponentAdapter(){
            public void componentResized(ComponentEvent e){updateTable();}
        });
    }

    public void setFilterLVL_label(){pred.setFilterLVL_label();}

    public void updateTable(){
        tp.updateTable();
        lp.setPreferredSize(new Dimension(segl2.getWidth()-4, segl2.getHeight() - HeatMap.HEIGHT_OF_HEATMAP - 42));
        scr.setBounds(0, 0, segl2.getWidth()-4, segl2.getHeight() - HeatMap.HEIGHT_OF_HEATMAP - 42);
        to.setBounds((segl2.getWidth() - (Center.WIDGE_WIDTH + Center.WIDGE_SIDE)), Center.WIDGE_TOP, Center.WIDGE_WIDTH, TableOpts.HEIGHT_OF_OPTIONS);
        setFilterLVL_label();
        pred.setBounds((segl2.getWidth() - (Center.WIDGE_WIDTH + Center.WIDGE_SIDE)), (segl2.getHeight() - (HeatMap.HEIGHT_OF_HEATMAP + Predator.HEIGHT_OF_PREDATOR  + 90)), Center.WIDGE_WIDTH, Predator.HEIGHT_OF_PREDATOR);
    }
}